<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
<head>
  <meta charset="UTF-8">
  <title>weather</title>
</head>
<body>
<div id="app">
  <input type="text" @keyup.enter="searchWeather" v-model="city" placeholder="请输入要查询的地区">
  <input type="submit" @click="searchWeather">
  <table v-show="weatherlist.length>0">
    <tr>
      <td>日期</td>
      <td>最高气温</td>
      <td>风力</td>
      <td>最低气温</td>
      <td>风向</td>
    </tr>
    <tr v-for="list in weatherlist">
      <td>{{list.date}}</td>
      <td>{{list.high}}</td>
      <td>{{list.fengli}}</td>
      <td>{{list.low}}</td>
      <td>{{list.fengxiang}}</td>
    </tr>
  </table>
</div>
<!--引入自己的js-->
<script>
  var app = new Vue({
    el: "#app",
    data: {
      weatherlist: [],
      city: '',
    },
    methods: {
      searchWeather: function () {
        // console.log("天气查询");
        // console.log(this.city);
        //保存this
        var that = this;
        axios.get('http://wthrcdn.etouch.cn/weather_mini?city=' + this.city)
          .then(function (response) {
            // console.log(response);
            // console.log(response.data.data.forecast);
            that.weatherlist = response.data.data.forecast;
          }).catch(function (err) {
        })
      }
    }
  })

</script>
</body>
</html>
